<template>
	<view class="content">
		<view class="header">
			<view class="title">
				<image class="title_img"
					src="https://goods.ruanmengkeji.cn/api/fileUp/4ce88c2c-7ec7-4c9f-aae5-cd2f97056bde.png" mode="">
				</image>
			</view>
		</view>
		<view class="login_box">
			<view class="login_title" @click="goSet">
				<image class="login_img" :src="userInfo ? userInfo.avatar : '../../static/img/loginimg.png'" mode="">
				</image>
				<view class="login_user">{{userInfo ? userInfo.name : "普通用户"}}</view>
			</view>
			<u-button v-if="false" :customStyle="customStyles" type="success" @click="gotoLogin">立即登录</u-button>
		</view>
		<!-- 实名认证 -->
		<view class="realName" v-if="loginState == 0" @click="goRealName">
			<view class="realBtn">
				去实名认证
			</view>
		</view>
		<!-- 会员卡余额 -->
		<view class="money" v-if="identityState == 1">
			<view class="money_item1">
				<p>--</p>
				<p>会员卡余额</p>
			</view>
			<view class="money_item1">
				<p>--</p>
				<p>积分</p>
			</view>
		</view>
		<view class="money" v-if="identityState == 2">
			<view class="money_item1">
				<p>{{worker ? worker.price : "--"}}</p>
				<p>员工卡余额</p>
			</view>
			<view class="money_item1">
				<p>{{worker ? worker.waitPrice : "--"}}</p>
				<p>职工卡待付余额</p>
			</view>
			<view class="money_item1">
				<p>{{worker ? worker.points : "--"}}</p>
				<p>积分</p>
			</view>
		</view>
		<view class="card_bigbox">
			<view class="card_box">
				<view class="card1">
					外卖点餐
				</view>
				<view class="card2">
					送货上门享美味
				</view>
				<view class="card3">
					<image class="card_img" src="../../static/img/waimai.png" mode=""></image>
				</view>
			</view>
			<view class="card_box">
				<view class="card1">
					堂食点餐
				</view>
				<view class="card2">
					快捷下单，无需排队
				</view>
				<view class="card3">
					<image class="card_img" src="../../static/img/store.png" mode=""></image>
				</view>
			</view>
		</view>
		<!-- 健康餐预定 -->
		<view class="scroll_title">
			健康餐预定
			<view class="srcoll_more" @click="goHmSe">
				更多
				<image src="../../static/img/more.png" mode=""></image>
			</view>
		</view>
		<view class="text-area">
			<scroll-view class="scroll-view_H" scroll-x enable-flex :bindscroll="scroll" style="width: 100%">
				<view class="scroll_box scroll-view-item_H" v-for="item,index in scrollValue" :key="index">
					<image class="scroll_img" :src="item.image" mode=""></image>
					<view class="tit_mon">
						<p class="title">{{ item.categoryName }}</p>
						<p class="price">￥{{ item.price }}</p>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 首页分类 -->
		<view class="classify_box">
			<!-- <u-tabs :list="list1"></u-tabs> -->
			<u-tabs :list="list1" @click="handelclick" :itemStyle='{
					
					fontSize: "28rpx",
					height: "70rpx",
					boxSizing: "border-box"
					}' :activeStyle='{
					color:"#5CAF5D",
					fontWeight: "bold",
			
					}' :inactiveStyle='{
					color:"#000000", 
					}' lineHeight='8rpx' lineColor="#5CAF5D">
			</u-tabs>
			<view class="classify_food" v-for="(item, index) in storeList" :key="index" @click="goToStoredetails">
				<view class="food_img">
					<image style="width: 210rpx;height: 140rpx;" :src="item.image" mode=""></image>
				</view>
				<view class="food_val">
					<view>
						<text class="title">{{item.name}}</text>
						<image style="width: 92rpx;height: 36rpx;" src="../../static/img/peisong.png" mode=""></image>
					</view>
					<view class="time">
						<p>营业时间：</p>
						<view class="time_text">
							{{item.amStartTime}}-{{item.amEndTime}} {{item.pmStartTime}}-{{item.pmEndTime}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import home from '@/api/home.js'
	export default {
		data() {
			return {
				userInfo: '',
				//员工卡
				worker: {
					price: "",
					waitPrice: "",
					points: ""
				},
				//会员卡
				vip: {
					price: "",
					points: "",
				},
				loginState: 0, //登录状态
				identityState: 0, //余额展示
				//健康餐列表
				scrollValue: [],
				list1: [{
					id: '',
					name: '全部',
				}, {
					id: 1,
					name: '餐饮',
				}, {
					id: 3,
					name: '食堂',
				}, {
					id: 4,
					name: '咖啡'
				}],
				//门店列表
				storeList: [],
				customStyles: {
					width: '164rpx',
					height: '64rpx',
					marginTop: '25rpx',
					fontSize: "25rpx"
				}
			}
		},
		onLoad() {
			let data = {
				id: ""
			}
			this.handelclick(data)
			this.getTime(1691293723000)
		},
		onShow() {
			this.getlon() //获取当前位置
			this.getCode() //获取sessonId
			this.getCardList() //获取卡列表
			this.healthPackage() //获取健康餐部分数据
		},
		methods: {
			click(item) {
				console.log('item', item);
			},
			goToStoredetails() {
				uni.navigateTo({
					url: "/homepage/storedeatils/storedeatils"
				})
			},
			handelclick(e) {
				home.getStoreList(e.id).then(res => {
					console.log(res);
					if (res.code == 0) {
						this.storeList = res.data
					}
				})
			},
			//修改个人信息
			goSet() {
				uni.navigateTo({
					url: '/homepage/setup/setup'
				})
			},
			//健康餐预定
			goHmSe() {
				uni.navigateTo({
					url: '/homepage/hmSchedule/hmSchedule'
				})
			},
			//获取位置
			getlon() {
				return new Promise((resolve, reject) => {
					let self = this
					uni.getLocation({
						geocode: true,
						type: 'wgs84',
						success: function(res) {
							const {
								latitude,
								longitude
							} = res
							resolve(res);
						},
						fail: function(error) {
							// console.log('获取位置信息失败:', error);
							if (error.errCode == 2) {
								uni.$u.toast('请先打开位置信息!');
							}
							reject(error);
						}
					});

				});
			},
			//获取code
			getCode() {
				uni.login({
					success: (res) => {
						this.getSession(res.code)
					},
				});
			},
			//获取session
			getSession(val) {
				home.authSession({
					code: val
				}).then(res => {
					if (res.code === 0) {
						uni.setStorageSync("data", res);
						this.userInfo = res.data.userInfo;
						console.log(this.userInfo);
						this.loginState = this.userInfo.isAuth === 1 ? 1 : 0;
					}
				});
			},
			//实名认证
			goRealName() {
				uni.navigateTo({
					url: '/homepage/nameauthentication/nameauthentication'
				})
			},
			isAuth() {

			},
			//获取卡列表
			getCardList() {
				if(uni.getStorageSync("data")){
					let id = uni.getStorageSync("data").data.userInfo.id
					home.getCardList(id).then(res => {
						if (res.code == 0) {
							if (res.data.length == 1) {
								this.identityState = 1
								this.vip.price = res.data.cardList[0].money
								this.vip.points = res.data.integral
							} else {
								this.identityState = 2
								this.worker.price = res.data.cardList[0].money
								this.worker.waitPrice = res.data.cardList[1].money
								this.worker.points = res.data.integral
							}
						}
					})
				}else{
					uni.$u.toast('请稍后重试!');
				}
			},
			//获取健康餐部分数据
			healthPackage() {
				home.healthPackage(false).then(res => {
					if (res.code == 0) {
						this.scrollValue = res.data
					}
				})
			},
			//转换时间
			getTime(val) {
				const date = new Date(val)
				const hours = date.getHours().toString().padStart(2, '0');
				const minutes = date.getMinutes().toString().padStart(2, '0');
				const time = `${hours}:${minutes}`
				return time
			}
		},
	}
</script>

<style lang="scss" scoped>
	.header {
		position: fixed;
		width: 750rpx;
		height: 676rpx;
		top: 0;
		left: 0;
		right: 0;
		height: calc(var(--status-bar-height) + 624rpx);
		/* 状态栏+导航栏高度 */
		// background-image: url('');
		/* 替换为你的图片路径 */
		background-repeat: no-repeat;
		background-position: center;
		background-size: cover;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: -1;
		/* 确保头部在其他元素之上 */
	}

	.title {
		color: white;
		font-size: 16px;
	}

	.title_img {
		width: 750rpx;
		height: 676rpx;
	}

	.card_bigbox {
		display: flex;
		justify-content: space-evenly;
		margin-top: 35rpx;
	}

	.card1 {
		font-family: PingFang SC, PingFang SC;
		color: #333333;
		font-weight: bolder;
		font-style: normal;
		text-transform: none;
	}

	.card2 {
		color: #999999;
	}

	.login_img {
		width: 72rpx;
		height: 72rpx;
		border-radius: 50%;
	}

	.login_box {
		width: 702rpx;
		height: 120rpx;
		margin: auto;
		margin-top: 673rpx;
		display: flex;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.login_title {
		margin-top: 25rpx;
		display: flex;
		text-align: center;
		margin-right: 250rpx;
		padding-left: 20rpx;
	}

	.realName {
		width: 710rpx;
		height: 160rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: white;
		margin: 10rpx auto;

		.realBtn {
			width: 348rpx;
			height: 64rpx;
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			background: #5CAF5D;
			text-align: center;
			line-height: 64rpx;
			color: white;
			font-size: 28rpx;
		}

	}

	.money {
		width: 710rpx;
		height: 160rpx;
		background: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 20rpx auto;

		.money_item1 {
			width: 355rpx;
			text-align: center;
			font-size: 28rpx;
		}

	}



	.login_user {
		margin-left: 20rpx;
		line-height: 76rpx;
		font-size: 25rpx;
	}

	.card_box {
		width: 344rpx;
		height: 286rpx;
		background-color: #fff;
		text-align: center;
		line-height: 65rpx;
	}

	.text-area {
		margin-left: 20rpx;
		margin-right: 20rpx;
		padding: 20rpx;
		background-color: #fff;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		box-sizing: border-box;
	}

	.card_img {
		width: 152rpx;
		height: 128rpx;

	}

	.scroll_img {
		width: 296rpx;
		height: 200rpx;
		border-radius: 12rpx;
	}

	.scroll_box {
		display: flex;

		.tit_mon {
			margin-top: -82rpx;
			background-color: #665649;
			width: 292rpx;
		}

		.title {
			width: 196rpx;
			height: 40rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 31rpx;
			color: #FFFFFF;
			line-height: 0rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
			margin-left: 14rpx;
		}

		.price {
			width: 102rpx;
			height: 34rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #FFFFFF;
			line-height: 0rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
			margin-left: 14rpx;
		}
	}

	.scroll-view_H {
		white-space: nowrap;
	}

	.scroll-view-item_H {
		display: inline-block;
		width: 47%;
		height: 226rpx;
	}

	.scroll_title {
		margin-top: 45rpx;
		margin-left: 20rpx;
		height: 44rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 32rpx;
		color: #333333;
		line-height: 0rpx;
		text-align: left;
		font-style: normal;
		text-transform: none;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.srcoll_more {
			font-size: 28rpx;
			color: #808080;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-right: 20rpx;
			width: 13%;

			image {
				width: 24rpx;
				height: 24rpx;
			}
		}
	}

	.classify_box {
		margin: -10rpx 20rpx 0 20rpx;
	}

	.classify_food {
		display: flex;
		background-color: #fff;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 20rpx;
		margin-top: 20rpx;

		.food_val {
			margin-left: 20rpx;
		}

		.title {
			display: inline-block;
			width: 343rpx;
			height: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 32rpx;
			color: #333333;
			line-height: 0rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}

		.sales {
			width: 120rpx;
			height: 34rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #7E7E7E;
			line-height: 0rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}

		.price_val {
			margin-top: 10rpx;
		}

		.price {
			width: 100rpx;
			height: 34rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #FF2020;
			line-height: 0rpx;
			text-align: left;
			font-style: normal;
			text-transform: none;
		}

		.time {
			// width: 406rpx;
			height: 34rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #333333;
			text-align: left;
			font-style: normal;
			margin-top: 30rpx;
			display: flex;

			>p {
				margin-right: 105rpx;
				width: 59%;
			}
		}
	}
</style>